
<%--
  Created by IntelliJ IDEA.
  User: LLS
  Date: 2020/3/10
  Time: 15:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>讨论区</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
</head>
<style>
    .layui-table-box,.layui-table-header {
        overflow: inherit;
    }
    #demo{
        margin-top: 30px;
    }
    body{
        background-color: #fff;
    }
</style>
<body>
<div>
    <div style="margin-top: 20px;position: relative;" class="head">
        <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_logProfile.png" style="position: absolute;left: 22px;top:4px ">
        <span style="margin-left: 49px;font-size: 22px;line-height: 35px;">讨论区</span>
        <button class="layui-btn allNotice" style="float: right;margin-right: 20px;">全局公告</button>
    </div>
    <table id="demo" lay-filter="demoEvent"></table>
</div>
<script type="application/javascript" >
    var table;
    var tableIns
    //创建实例对象
    layui.use(['table'],function () {
        //引用实例
        table=layui.table;
        //第一个实例
         tableIns=table.render({
            elem: '#demo'
            ,url: '/system/bbs/selAll' //数据接口
             ,where:{
                "purview":true
             }
            ,page: false //开启分页
            ,cols: [[ //表头
                {field: 'boardName', title: '讨论区', align:"center",event: 'board',style:'color: #1687cb;'}
                ,{field: 'anonymityYn', title: '发帖', align:"center",templet:function (d) {
                        if(d.anonymityYn==0){
                            return "禁止匿名"
                        }else if(d.anonymityYn==1){
                            return "允许匿名"
                        }else{
                            return "允许发帖"
                        }
                    }}
                ,{field: 'needCheck', title: '审核',align:"center",templet:function (d) {
                        if(d.needCheck==1){
                            return "需要审核"
                        }else{
                            return "不需审核"
                        }
                    }
                }
                ,{field: 'themeNums', title: '主题', align:"center"}
                ,{field: 'postNums', title: '帖数', align:"center"}
                ,{title: '最后发表', align:"center",event: 'lasthair',style:'color: #1687cb;',templet:function (d) {
                        if(d.lastRelease!=undefined){
                            if (d.lastRelease["authorName"]==undefined){
                                d.lastRelease["authorName"]="";
                            }
                            if (d.lastRelease["submitTime"]==undefined){
                                d.lastRelease["submitTime"]="";
                            }
                            if (d.lastRelease["authorName"]==undefined && d.lastRelease["submitTime"]==undefined){
                                return "";
                            }
                            return d.lastRelease["authorName"]+" by "+d.lastRelease["submitTime"]
                        }else{
                            return ''
                        }

                    }
                }
                ,{field: 'experience', title: '版主',align:"center",templet:function (d) {
                        if(d.boardHosterName!=undefined){
                            return d.boardHosterName
                        }else{
                            return ''
                        }
                    }}
            ]]
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "data": res.obj //解析数据列表
                };
            }
        });

        //监听单元格事件
        table.on('tool(demoEvent)', function(obj){
            var data = obj.data;
            if(obj.event === 'board'){
                window.location.href="/bbs/theme?boardId="+data.boardId+'&isCheck='+data.needCheck;
            }else if(obj.event === 'lasthair'){
                var lastRelease=data.lastRelease;
                if (lastRelease===undefined){
                    return false;
                }
                window.location.href="/bbs/article?commentId="+lastRelease.commentId+'&boardId='+lastRelease.boardId+'&isCheck='+data.needCheck;

            }
        });

    });

    //全局公告
    $('.allNotice').click(function () {
        layer.open({
            type: 2
            ,title: ['全局公告', 'font-size:18px;']
            ,maxmin:true
            ,area: ['90%', '90%']
            ,content: '/bbs/allNotice?boardId=-1'
            ,btn:['保存','关闭']
            ,btnAlign: 'c'
            ,yes: function(index, layero){
                //按钮【按钮一】的回调
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
                tableIns.reload()
            }
        });
    })

    function layertrue(flag) {
        if (flag) {
            layer.msg('成功', {icon: 6}, function(){
                layer.closeAll();
            });
        } else {
            layer.msg('失败', {icon: 5},function(){
                layer.closeAll();
            });
        }
    }
</script>
</body>
</html>
